// const jsonwebtoken=require('jsonwebtoken')
const jwt=require('koa-jwt')
const Router=require('koa-router')
const router=new Router({prefix:'/topics'}) //添加前缀，后续写可省略前缀
const {find,findById,create,update, listFollowers,checkTopicExist} =require('../controllers/topics')
const {secret} =require('../config')

const auth=jwt({secret})


router.get('/',find)
router.post('/',auth,create)
router.get('/:id',checkTopicExist,findById)
router.patch('/:id',auth,checkTopicExist,update)  //put整体替换，patch可局部更新
router.get('/:id/followers',checkTopicExist,listFollowers)


module.exports=router